import http from './interface'
import store from '@/store'
//设置请求前拦截器
http.interceptor.request = (config) => {
	console.log("====--++++++--"+store.state.userInfo.token)
	config.header = {
		'token': store.state.userInfo.token,
	}

}
//设置请求结束后拦截器
http.interceptor.response = (response) => {
	console.log("=============--------"+store.state.userInfo.token)
	uni.hideLoading()
	if(response.statusCode === 200){
		if ( response.data.code === 20001 || response.data.code === 20002) {
			//未登录
			uni.showToast({
				title: response.data.message,
				duration: 1200,
				icon: 'none'
			})
		setTimeout(function() {
			uni.reLaunch({
				url: '/pages/mine/author',
				animationType: 'slide-in-bottom',
				"animationDuration": 450
			});
			console.log('拦截拦截拦截')
		}, 450);
			store.commit('logout')
			return
		}
	}else{
		uni.showToast({
			title: '网络好像不太通畅~',
			duration: 1200,
			icon: 'none'
		})
	}

}

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 *
 */

export const awaitorderreceiving = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/accompany/order_receiving/await_order_receiving',
		method: 'POST',
		data
	})
}
export const orderok = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/order_ok',
		method: 'POST',
		data
	})
}
export const orderdetails = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/order_details',
		method: 'POST',
		data
	})
}
export const alreadyorderreceiving = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/accompany/order_receiving/already_order_receiving',
		method: 'POST',
		data
	})
}
export const accompanyAttestation = (data) => {
	return http.request({
		url: 'api/accompany/accompanyAttestation',
		method: 'POST',
		data
	})
}
export const getUserInfo = (data) => {
	return http.request({
		url: 'api/accompany/accompany_centre',
		method: 'POST',
		data
	})
}
export const walletdetails = (data) => {
	return http.request({
		url: 'api/accompany/wallet_details',
		method: 'POST',
		data
	})
}
export const remainingbalance = (data) => {
	return http.request({
		url: 'api/accompany/remaining_balance',
		method: 'POST',
		data
	})
}
export const fivedetails = (data) => {
	return http.request({
		url: 'api/accompany/five_details',
		method: 'POST',
		data
	})
}
export const myorder = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/accompany/order_receiving/my_order',
		method: 'POST',
		data
	})
}
export const userevaluate = (data,pageNum,pageSize) => {
	http.interceptor.request = (config) => {
		config.header = {
			'pageNum': pageNum,
			'pageSize': pageSize,
			'token':  store.state.userInfo.token
		}
	}
	return http.request({
		url: 'api/accompany/order_receiving/user_evaluate',
		method: 'POST',
		data
	})
}
export const getQRcode = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/QR_code',
		method: 'POST',
		data
	})
}
export const decode = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/decode',
		method: 'POST',
		data
	})
}
export const vitedtorecord = (data) => {
	return http.request({
		url: 'api/accompany/invited_to_record',
		method: 'POST',
		data
	})
}
export const orderreceivingstatus = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/order_receiving_status',
		method: 'POST',
		data
	})
}
export const submitdata = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/submit_data ',
		method: 'POST',
		data
	})
}
export const serviceover = (data) => {
	return http.request({
		url: 'api/accompany/order_receiving/service_over',
		method: 'POST',
		data
	})
}
export const wxdrawings = (data) => {
	return http.request({
		url: 'api/wx_pay/wx_drawings',
		method: 'POST',
		data
	})
}
export const wxpax = (data) => {
	return http.request({
		url: 'api/wx_pay/wx_pax',
		method: 'POST',
		data
	})
}
export default {
	awaitorderreceiving,
	orderok,
	orderdetails,
	alreadyorderreceiving,
	accompanyAttestation,
	getUserInfo,
	walletdetails,
	fivedetails,
	remainingbalance,
	myorder,
	userevaluate,
	getQRcode,
	decode,
	vitedtorecord,
	orderreceivingstatus,
	submitdata,
	serviceover,
	wxdrawings,
	wxpax
}
